var UserID = "";
var exist = 0;

mui.plusReady(function() {
	var server = localStorage.getItem('ServerHttp');
	if (!server) {
		localStorage.setItem('ServerHttp', $("#ServerHttp").val());
	} else {
		$("#ServerHttp").val(localStorage.getItem('ServerHttp'));
		//$("#ServerHttp").val("http://192.168.100.200:7002/");
	}
	//测试环境下端口
	//$("#ServerHttp").val("http://192.168.1.24:7001/");
	//$("#ServerHttp").val("http://192.168.100.200:7002/");
	//$("#ServerHttp").val("http://192.168.1.3:7002/");
	//$("#ServerHttp").val("http://192.168.100.198:7002/");
	//$("#ServerHttp").val("http://192.168.1.247:7002/");
	//$("#ServerHttp").val("http://192.168.103.195:7002/");
	$("#ServerHttp").val("http://10.168.1.108:8080/");
})
// 使手机键盘弹出时不顶上协议一行字
var win_h = $(window).height(); //关键代码
window.addEventListener('resize', function() {
	if ($(window).height() < win_h) {
		$(".protocols-box").hide();
	} else {
		$(".protocols-box").show();
	}
});

//账号密码登录
function CheckLogin() {
	//获取前端服务器文本框 正式环境
	var Serverhttp = $("#ServerHttp").val();
	//服务器路径赋值
	httpurl6 = httpurl5 = httpurl4 = httpurl3 = httpurl2 = httpurl1 = Serverhttp;

	var UserNO = $("#UserNO").val();
	var Pwd = $("#Pwd").val();
	if (UserNO == "" || UserNO == null) {
		mui.toast("请输入用户名");
		return;
	}
	if (Pwd == "" || Pwd == null) {
		mui.toast("请输入密码");
		return;
	}
	var check = document.getElementById('remember');
	xccpostAsync("api/PDA/Login", {
		UserNO: UserNO,
		Pwd: Pwd
	}, function(data) {
		if (data.Code == 200) {
			if (check.checked) { //勾选就会保存
				localStorage.setItem('Pwd', Pwd);
			} else { //取消勾选就会取消保存
				localStorage.setItem('Pwd', '');
			}
			localStorage.setItem("UserName", data.Items[0].UserName);
			localStorage.setItem("UserNO", data.Items[0].UserNO);
			if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
				plus.nativeUI.showWaiting();
			};

			setTimeout(function() {
				mui.openWindow({
					url: 'project/html/MainPage.html',
					action: data.Items[0].UserName

				});
			}, 100);

			plus.nativeUI.closeWaiting();


		} else if (data.Code == "500") {
			mui.toast("账号或密码错误", {
				duration: '1000',
				type: 'div'
			});
			$("#Pwd").val("");
			$("#Pwd").focus();
			//p判断是PC端
			if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
				plus.nativeUI.closeWaiting();
			}
		}
	}, function() {
		//p判断是PC端
		if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
			plus.nativeUI.closeWaiting();
		}
	})

}